package com.atguigu.fink.chapter01.timeattr;

import org.apache.flink.configuration.Configuration;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.table.api.bridge.java.StreamTableEnvironment;

/**
 * @Author lzc
 * @Date 2022/11/28 09:06
 */
public class Flink02_SQL_Time_Event {
    public static void main(String[] args) throws Exception {
        Configuration conf = new Configuration();
        conf.setInteger("rest.port", 2000);
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment(conf);
        env.setParallelism(1);
       
        StreamTableEnvironment tEnv = StreamTableEnvironment.create(env);
        
        // 1. 建立一个动态表语句文件关联
        tEnv.executeSql("create table sensor(" +
                            "id string, " +
                            "ts bigint, " +
                            "vc int, " +
                            // 时间属性必须是: 时间戳类型
                            // bigint -> timestamp
                            "et as to_timestamp_ltz(ts, 3), " +
                            "watermark for et as et - interval '3' second" +
                            ")with(" +
                            " 'connector'='filesystem',  " +
                            " 'path'='input/sensor.txt',  " +
                            " 'format'='csv'  " +
                            ")");
        
        tEnv.sqlQuery("select * from sensor").execute().print();
    
      
    
    }
}
